const bucket = new WeakMap();

function reactive(data) {
    if (typeof data !== "object") return
    return new Proxy(data, {
        get(target, key) {
            track(target, key);
            return target[key]
        },
        set(target, key, value) {
            trigger(target, key)
            target[key] = value;
            return true;
        }
    })
}

function affect(fn) {

}

function track(target, key) {
    let set = bucket.get(target)||new Set();
    set.add(target)
}

function trigger(target, key) {
    let set = bucket.get(target);
    if (set.get(key)) {
        set.forEach(fn => fn());
    }
}